﻿using Autofac;
using System.Reflection;
using Module = Autofac.Module;

namespace rbac.API
{
    /// <summary>
    /// Autofac注册服务类
    /// </summary>
    public class AutofacModuleRegister:Module
    {
        protected override void Load(ContainerBuilder builder)
        {
            // 批量注册服务
            builder.RegisterAssemblyTypes(
                        Assembly.Load("rbac.Services")
                        , Assembly.Load("rbac.Contracts")
                    )
                .Where(a => a.Name.EndsWith("Service")).AsImplementedInterfaces();

            builder.RegisterAssemblyTypes(
                    Assembly.Load("rbac.Domain")
                )
                .Where(a => a.Name.EndsWith("Repository")).AsImplementedInterfaces();

            builder.RegisterType<TokenService>();

        }
    }

}
